﻿using FluentValidation;

namespace FE.Shared.Validator
{
    public class ServerPathSettingsValidator : AbstractValidator<ServerPathSettings>
    {
        private const string NotNullStr = "不能为空!";

        public ServerPathSettingsValidator()
        {
            RuleFor(x => x.FileMode).GreaterThanOrEqualTo(1).LessThanOrEqualTo(2);

            //文件夹不能为空验证
            When(x => x.FileMode == 1, () =>
            {
                RuleFor(x => x.PdfGeneratedServerPath).NotNull().Length(1, 200).WithMessage("附件上传根目录路径" + NotNullStr);
                RuleFor(x => x.FileAttachmentRootPath).NotNull().Length(1, 200).WithMessage("生成PDF的路径" + NotNullStr);
            });

            //sftp验证
            When(x => x.FileMode == 2, () =>
            {
                RuleFor(x => x.SftpFileAttachmentRootPath.Host).NotNull().Length(1, 200).WithMessage("SFTP服务器地址" + NotNullStr);
                RuleFor(x => x.SftpFileAttachmentRootPath.Path).NotNull().Length(1, 200).WithMessage("文件夹路径" + NotNullStr);
                RuleFor(x => x.SftpFileAttachmentRootPath.UserName).NotNull().Length(1, 50).WithMessage("账号" + NotNullStr);
                RuleFor(x => x.SftpFileAttachmentRootPath.Password).NotNull().Length(1, 50).WithMessage("密码" + NotNullStr);

                RuleFor(x => x.SftpPdfGeneratedServerPath.Host).NotNull().Length(1, 200).WithMessage("SFTP服务器地址" + NotNullStr); 
                RuleFor(x => x.SftpPdfGeneratedServerPath.Path).NotNull().Length(1, 200).WithMessage("文件夹路径" + NotNullStr); 
                RuleFor(x => x.SftpPdfGeneratedServerPath.UserName).NotNull().Length(1, 50).WithMessage("账号" + NotNullStr);
                RuleFor(x => x.SftpPdfGeneratedServerPath.Password).NotNull().Length(1, 50).WithMessage("密码" + NotNullStr);
            });
        }
    }
}